//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/.
//          VisualNovelToolkit           /_/_/_/_/_/_/_/_/_/.
// Copyright ©2013 - Sol-tribe. /_/_/_/_/_/_/_/_/_/.
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/.

using UnityEditor;
using UnityEngine;

namespace ViNoToolkit{

    public class SceneCreateWizard : ScriptableWizard {
        public string sceneName;
        public Texture2D texture;    

        [MenuItem ("GameObject/Create Scene Data")]
        static void CreateWizard () {
            ScriptableWizard.DisplayWizard<SceneCreateWizard>("Create your Scene", "Create" );
        }

         [MenuItem( "Assets/Add to Scene...")]
        static public void AddToScene(){
            Texture2D tex = Selection.activeObject as Texture2D;
            if( tex ){                
                SceneEvent se = GameObject.FindObjectOfType(typeof(SceneEvent)) as SceneEvent;
                foreach(Scene s in se.sceneLib.sceneEntries ){
                    if( s.name == tex.name ){
                        EditorUtility.DisplayDialog( "Warning" , "The Texture name scene is already exist." , "ok" );
                        return;
                    }
                }

                Scene scene = CreateScene( tex.name ,  tex );

                if( se && se.sceneLib ){
                    ArrayUtility.Add<Scene>( ref se.sceneLib.sceneEntries , scene );

                    ViNoEditorGUILayout.CollectSceneNamesInSceneLibrary();
                }
            }
        }

        static public Scene CreateScene( string sceneName , Texture2D texture ){
            if( ! System.IO.Directory.Exists( "Assets/Scenes") ){
                AssetDatabase.CreateFolder( "Assets" , "Scenes" );
            }

            Scene scene = ScriptableObjectUtility.CreateScriptableObject( "Scene" , "Assets/Scenes/" + sceneName + ".asset") as Scene;
            ViNoSceneUtil.SetUpSceneInfo( scene , sceneName , "BG/" + texture.name );

            EditorGUIUtility.PingObject( scene );            

            return scene;
        }

        void OnWizardCreate () {
            EditorUtility.DisplayDialog( "Note" , "Please check that the BG Texture is placed at under a \"Resources/BG/\" folder." , "ok" );

            CreateScene( sceneName , texture );
        }  
        
    }
}